public class MoveThread implements Runnable {
    private final Object game;
    private boolean pause = false;

    public MoveThread(Object game) {
        this.game = game;
    }


    public void gameContinue() {
        pause = false;
        synchronized (game) {
            /*try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
            game.notify();
        }
    }

    public void gamePause() {
        pause = true;
    }

    @Override
    public void run() {
        while (true) {
            int time = TimeThread.time;//局时
            int lengthLimit = (int) (MainFrame.GRID_NUMBER * MainFrame.GRID_NUMBER * 0.2);
            int length = MainFrame.length;
            int lengthSleep = (int) ((-90.0 / (lengthLimit * lengthLimit)) * length * length);
            //System.out.println("length:"+length);
            //System.out.println("--->" + lengthSleep);

            while (pause) {
                synchronized (game) {
                    try {
                        game.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            try {
                //睡眠时间
                int sleep = 0;
                if (time <= 600) {
                    if (length <= lengthLimit) {
                        sleep = 100 + (100 + (time / -6) + lengthSleep + 100);
                    } else {
                        sleep = 100 + (100 + (time / -6));
                    }
                } else {
                    if (length <= lengthLimit) {
                        sleep = 100 + lengthSleep + 100;
                    } else {
                        sleep = 100;
                    }
                }
                //System.out.println(sleep);
                Thread.sleep(sleep);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            MainFrame.currentPath(MainFrame.direct);
        }

    }
}
